package com.example.newspublish.controller;

import com.example.newspublish.service.FileUploadService;
import com.example.newspublish.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
@Slf4j
@RestController
@RequestMapping("/files")
@Tag(name = "文件模块")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    @Operation(summary = "文件上传")
    @PostMapping("/upload")
    public Result uploadFile(@RequestPart("file") MultipartFile file) throws Exception {
        System.out.println("文件请求上传~");
        String fileUrl = fileUploadService.uploadImage(file);
        return Result.success("上传成功~",fileUrl);
    }
}
